require.config({
	paths: {
		"jquery":"jquery-1.11.3",
		"cookie":"jquery.cookie",
		"Animation":"requestAnimationFrame"
	}
});
//main.js
require(["jquery","cookie","Animation"],function($,cookie,Animation){
		$.getJSON("../json/LAMIU_one.json",function(json){
	//		console.log($("#hot").eq(0));
			//top栏
			$("#headerCon a").hover(
				function(){
					$(this).css("color","rgb(204,204,204)");
				},
				function(){
					$(this).css("color","#000");
				}
			);
			//如果能获取到登录账号密码cookie值 就改掉主页的内容
			var users = $.cookie("loginedUsers") ? $.cookie("loginedUsers") : "" ;
			if(users){
				$(".loginIn a").html("欢迎您，尊敬的用户"+users);
				$(".registerOne a").html("");				
			}
			//search栏
			$("#hot").children().eq(1).html(json.search1);
			$("#hot").children().eq(2).html(json.search2);
			$("#hot").children().eq(3).html(json.search3);
			$("#forSale").attr("src",json.forSale);
			//console.log($("#headerCon a"));
			
			//menu栏
			var $VMenuList = $("#verticalMenu").children();
			$VMenuList.each(function(){
				$(this).css("background","url("+ json.MenubottomImg +") no-repeat center bottom");
			});
			//点击横向列表里的首页 跳转到首页
			$(".horMenuOne").click(function(){
				location.href = "LAMIU_one.html";
			});
			var $HMenuList = $("#horizontalMenu").children();
			$HMenuList.not("#horMenuOne").not("#allGoods").each(function(){
				$(this).hover(
					function(){
						$(this).css("color","#f19ec2");
					},
					function(){
						$(this).css("color","#000");
					}
				);
			});
			$("#verticalMenu li>a").hover(
				function(){
					$(this).css("font-weight","700");
				},
				function(){
					$(this).css("font-weight","300");
				}
			);
			//二级菜单
			$("#verticalMenu").children().each(function(){
				$(this).removeClass("active");
				$(this).hover(
					function(){
						$(this).addClass("active");
					},
					function(){
						$(this).removeClass("active");
					}
				);
			});
			$("#VMImg").attr("src",json.VMImg);
			
			//购物车
			$("#shoppingCart").hover(
				function(){
					$(this).first().css({"background-color":"white","border":"1px solid #e9e9e9e","height":"42px"});
					$("#goodsList").show();
				},
				function(){
					$("body").click(function(){
						$("#shoppingCart").first().css({"background":"none","border":"none","height":"40px"});
						$("#goodsList").hide();
					});
				}
			);
			
			//banner图轮播部分
			var curIndex = 0;
			var autoChange = setInterval(function(){
				if(curIndex < json.banner.length-1){
					curIndex++
				}else{
					curIndex = 0;
				}
				$("#bannerImg").attr("src",json.banner[curIndex]);
				changeTo(curIndex);
			},2500)
			
			$("#sequenceList").find("li").each(function(item){
				$(this).hover(
					function(){
						clearInterval(autoChange);
						changeTo(item);
						curIndex = item;
						$("#bannerImg").attr("src",json.banner[curIndex]);
					},
					function(){
						autoChange = setInterval(function(){
							if(curIndex < json.banner.length-1){
								curIndex++
							}else{
								curIndex = 0;
							}
							$("#bannerImg").attr("src",json.banner[curIndex]);
							changeTo(curIndex);
						},2500);
					});		
			});
			
			$("#bannerWrap").mouseover(function(){
				clearInterval(autoChange);
			});
			$("#bannerWrap").mouseout(function(){
				autoChange = setInterval(function(){
					if(curIndex < json.banner.length-1){
						curIndex++
					}else{
						curIndex = 0;
					}
					$("#bannerImg").attr("src",json.banner[curIndex]);
					changeTo(curIndex);
				},2500);
			});
			function changeTo(num){
				$("#bannerImg").hide().fadeIn(500);
				$("#sequenceList").find("li").removeClass("colorOn").eq(num).addClass("colorOn");
			};
			
			//侧边栏
			$("#slidebar").find(".pinkA").hover(
				function(){
					$(this).css("background-color","#f53998");
				},
				function(){
					$(this).css("background-color","#000");
				}	
			);
			
			$("#cart_qqSevice").click(
				function(){
					$("#qqSevice_show").show();
				}
			);
			$("#back_btn").click(
				function(){
					$("#qqSevice_show").hide();
				}
			);
			/*回到顶部*/
			$("#slide_backToTop").click(
				function(){
					$("body").scrollTop(0);
				}
			);
			
			/*商品信息*/
			/*类型选择区域*/
			for(var i = 0;i < $(".hotBrand_ul li").length;i ++){
				var $div = "<div class='ulBanner'><a href='http://www.lamiu.com/gallery-123.html' target='_blank'><img alt width='235' height='62' src="+json.hotBrand[i]+"/></a></div>";
				$(".hotBrand_ul li").eq(i).append($div);
			}
			
			for(var i = 0;i < $(".hotAd_ul li").length;i ++){
				var $div = "<div class='ulBanner'><a href='http://www.lamiu.com/gallery-123.html' target='_blank'><img src="+json.hotAd[i]+"/></a></div>";
				$(".hotAd_ul li").eq(i).append($div);
			}
			
			/*物品信息列表区域*/
			/*前两个列表的公共部分*/
			for(var j = 0;j < $(".selectionList").length;j ++){
				var $j = ""+j;
				var $href = json.seList["seList" + $j];
				var $seListTitle = "<div class='seList_title'><h3 class='topTitle'><a href='http://www.lamiu.com/gallery-22.html' target='_blank'><img src="+$href.seListTitle+" alt width='1000' height='27' border='0'/></a></h3></div>";
				var $seListBanner = "<div class='seList_banner'><a target='_blank'><img alt src="+$href.w320+"/></a></div>";
				var $seListMain = "<div class='seList_main'><div class='w320 fl'></div><div class='w680 fl'><ul class='w680_ul'><li></li><li></li><li></li><li></li></ul></div></div>";
				
				
				var $seList_j = $(".selectionList").eq(j);
				
				$(".selectionList").eq(j).append($seListTitle);
				$seList_j.append($seListMain);
				$seList_j.find(".w320").append($seListBanner);
				
				for(var i = 0;i < $seList_j.find(".w680_ul").find("li").length;i ++){
					var $w680Banner = "<div class='seList_banner'><a target='_blank'><img alt src="+$href.w680[i]+"/></a></div>";
					
					$seList_j.find(".w680_ul").find("li").eq(i).append($w680Banner);
				}
				
			}
				//第一个列表的独特部分
				var $seList_zero = $(".selectionList").eq(0);
				var $proList1 = "<div class='longAd proList'><ul class='goodsList'><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li></ul></div>";
				$seList_zero.append($proList1);
				$seList_zero.find(".proList").find(".goodsList").find("li").addClass("goodsitem");
				
				
				for(var k = 0;k < $seList_zero.find(".goodsList").find(".goodsitem").length;k ++){
					var $href1 = json.seList.seList0;
					var $k = "" + k;
					var $goodsMessage = $href1.proList["proLi" + $k];
					var $goodsLi = "<div class='goodsPic'><a target='_blank'><img alt="+$goodsMessage[1]+" src="+$goodsMessage[0]+"/></a></div><h3 class='goodsName'><a href='###' title="+$goodsMessage[1]+" target='_blank'>"+$goodsMessage[1]+"</a></h3><div class='goodsPrice'><del class='marketPrice'><span>售价:"+$goodsMessage[2]+"</span><i></i></del><ins class='sellingPrice'><i>折扣价: "+$goodsMessage[3]+"</i></ins></div>";
					$seList_zero.find(".goodsList").find("li").eq(k).append($goodsLi);
		}
				
				//第二个列表的独特部分  需要循环填加四个ul	
				var $seList_one = $(".selectionList").eq(1);
				for(var i = 0;i < 4;i ++){
//					console.log("%c"+i,"color:green;font-weight:bold");
					var $i = "" + i;
					var $hrefgoods = json.seList.seList1.goodsList["goodsList" + $i];					
					var $goodsList1 = '<img src="'+ $hrefgoods.titleImg +'"/>'+
								  '<ul class="goodsList">'+
								  	'<li></li>'+
								  	'<li></li>'+
								  	'<li></li>'+
								  	'<li></li>'+
								  	'<li></li>'+
								  	'<li></li>'+
								  	'<li></li>'+
								  	'<li></li>'+
								  '</ul>';
					$seList_one.append($goodsList1);	
					$seList_one.find(".goodsList").eq(i).find("li").addClass("goodsitem");
					var gitems = $seList_one.find(".goodsList").eq(i).find(".goodsitem").length; //少写了eq(i) 每一个li都有这个类名 两次以后 就会变成16个 此时json里的数据不够 就会undefined
					for(var j = 0;j < gitems;j ++){
						var $j = "" + j;
						var $goodsmes = $hrefgoods.listImg["listImg" + $j];
						
						var $goodsLis = '<div class="goodsPic">'+
											'<a href="###" target="_blank">'+
												'<img alt="'+$goodsmes[1]+'" src="'+$goodsmes[0]+'"/>'+
											'</a>'+
										'</div>'+
										'<h3 class="goodsName">'+
											'<a href="###" title="'+$goodsmes[1]+'" target="_blank">"'+$goodsmes[1]+'"</a>'+
										'</h3>'+
										'<div class="goodsPrice">'+
											'<del class="marketPrice"><span>售价:"'+$goodsmes[2]+'"</span><i></i></del>'+
											'<ins class="sellingPrice"><i>折扣价: "'+$goodsmes[3]+'"</i></ins>'+
										'</div>';
						$seList_one.find(".goodsList").eq(i).find("li").eq(j).append($goodsLis);			
					}	
				}	
			//下面两个商品列表
			for(var j = 0;j < $(".selections").length;j ++){
				var $j = ""+j;
				
				var $hrefLast = json.seList.seList2["lastList" + $j];
				var $seListTitle = "<div class='seList_title'><h3 class='topTitle'><a href='http://www.lamiu.com/gallery-22.html' target='_blank'><img src="+$hrefLast.titleImg+" alt width='1000' height='27' border='0'/></a></h3></div>";
				var $seListMain = '<div class="seList_main"><div class="w490 fl"></div><div class="w490 fr"></div></div>';
				var $g_list = '<div class="proList">'+
									'<ul class="goodsList">'+
									'<li></li>'+
									'<li></li>'+
									'<li></li>'+
									'<li></li>'+
									'</ul>'+
								'</div>';
				
				var $seList_j = $(".selections").eq(j);
				$(".selections").eq(j).append($seListTitle);
				$seList_j.append($seListMain);
				$seList_j.append($g_list);
				$seList_j.find(".goodsList").find("li").addClass("goodsitem");
				//往w490里加图片
				for(var i = 0;i < $seList_j.find(".w490").length;i ++){
					var $w490Banner = "<div class='seList_banner'><a href='http://www.lamiu.com/product-19754.html' target='_blank'><img alt src="+$hrefLast.w490[i]+"/></a></div>";
					
					$seList_j.find(".w490").eq(i).append($w490Banner);
				}
				//往g_list里加东西
				var gitems = $seList_j.find(".proList").find(".goodsList").find("li").length;
				for(var k = 0;k < gitems;k ++){
						var $k = "" + k;
						var $goodsmes = $hrefLast.lastLists["lastLists" + $k];
						
						var $goodsLis = '<div class="goodsPic">'+
											'<a href="###" target="_blank">'+
												'<img alt="'+$goodsmes[1]+'" src="'+$goodsmes[0]+'"/>'+
											'</a>'+
										'</div>'+
										'<h3 class="goodsName">'+
											'<a href="###" title="'+$goodsmes[1]+'" target="_blank">"'+$goodsmes[1]+'"</a>'+
										'</h3>'+
										'<div class="goodsPrice">'+
											'<del class="marketPrice"><span>售价:"'+$goodsmes[2]+'"</span><i></i></del>'+
											'<ins class="sellingPrice"><i>折扣价: "'+$goodsmes[3]+'"</i></ins>'+
										'</div>';
						$seList_j.find(".goodsList").find("li").eq(k).append($goodsLis);			
					}	
			}
			//空列表
			
			for(var i = 0;i < $(".blank").length;i ++){
				var $seListTitle = '<div class="seList_title">'+
										'<h3 class="topTitle">'+
										'</h3>'+
									'</div>';
				var $seListMain = '<div class="seList_main">'+
										'<div class="w490 fl">'+
										'</div>'+
										'<div class="w490 fr">'+
										'</div>'+
									'</div>';
				var $g_list = '<div class="proList"></div>'	;
				$(".blank").eq(i).append($seListTitle);
				$(".blank").eq(i).append($seListMain);
				$(".blank").eq(i).append($g_list);
			}
			
			//猜你喜欢
			for(var i = 0;i < $(".maybeLike").length;i ++){
				var $i = "" + i;
				var $hrefML = json.seList.seList2.lastList2;
				var $seListTitle = '<div class="seList_title">'+
										'<h3 class="topTitle">'+
											'<a href="http://www.lamiu.com/gallery-22.html" target="_blank">'+
												'<img src="'+$hrefML.titleImg+'" alt width="1000" height="27" border="0"/>'+
											'</a>'+
										'</h3>'+
									'</div>';
				var $g_list = '<div class="proList">'+
									'<ul class="goodsList">'+
									'<li></li>'+
									'<li></li>'+
									'<li></li>'+
									'<li></li>'+
									'</ul>'+
								'</div>';					
				$(".maybeLike").append($seListTitle);
				$(".maybeLike").append($g_list);
				$(".maybeLike").find(".proList").find(".goodsList").find("li").addClass("goodsitem");
				
				var gitems = $(".maybeLike").find(".proList").find(".goodsList").find("li").length;
				for(var k = 0;k < gitems;k ++){
						var $k = "" + k;
						var $goodsmes = $hrefML.lastLists["lastLists" + $k];
						
						var $goodsLis = '<div class="goodsPic">'+
											'<a href="###" target="_blank">'+
												'<img alt="'+$goodsmes[1]+'" src="'+$goodsmes[0]+'"/>'+
											'</a>'+
										'</div>'+
										'<h3 class="goodsName">'+
											'<a href="###" title="'+$goodsmes[1]+'" target="_blank">"'+$goodsmes[1]+'"</a>'+
										'</h3>'+
										'<div class="goodsPrice">'+
											'<del class="marketPrice"><span>售价:"'+$goodsmes[2]+'"</span><i></i></del>'+
											'<ins class="sellingPrice"><i>折扣价: "'+$goodsmes[3]+'"</i></ins>'+
										'</div>';
						$(".maybeLike").find(".goodsList").find("li").eq(k).append($goodsLis);			
					}	
			}
			//评论区			
			var $w490 = '<div class="w490 fl">'+
						'</div>'+
						'<div class="w490 fr">'+
						'</div>';
			$(".comments").append($w490);
			for(var j = 0;j < $(".comments").find(".w490").length;j ++){
				var $j = "" + j;
				var $hrefCom = json.seList.seList3["comment"+$j];					
				var $comments_title = '<div class="seList_title">'+
										'<h3 class="topTitle">'+
											'<a href="http://www.lamiu.com/gallery-22.html" target="_blank">'+
												'<img src="'+$hrefCom.titleImg+'" alt width="1000" height="27" border="0"/>'+
											'</a>'+
										'</h3>'+
									'</div>';
				var $comments_list = '<div class="g_main g_comment">'+
										'<ul>'+
											'<li></li>'+
											'<li></li>'+
											'<li></li>'+
											'<li></li>'+
											'<li></li>'+
										'</ul>'+
									'</div>';
									
				var $com_j = $(".comments").find(".w490").eq(j);				
				$com_j.append($comments_title);	
				$com_j.append($comments_list);
				var $comList = $com_j.find(".g_comment").find("ul").find("li")
				for(var i = 0;i < $comList.length;i ++){
					var  $comLis = '<a type="url" target="_blank">"'+ $hrefCom.comments[i] +'"</a>'
					$comList.eq(i).append($comLis);
				}
			}
		/*还有底部 明天写完购物车*/	
		/*随高度出现的侧栏*/
		$(".slideListener").find("a").hover(
			function(){
				$(this).css("color","#f53598");
			},
			function(){
				$(this).css("color","#fff");
			}
		);
		$(window).scroll(
			function(){
				if($(window).scrollTop() > 720 && $(window).scrollTop() < 8000){
					$(".slideListener").css("display","block");
				}else{
					$(".slideListener").css("display","none");
				}
			}
		);
		
		/*给所有图片加上自定义属性*/
//		console.log(typeof $("img"));
		
		/*$("img").each(function(index,value){
			console.log(typeof $(this).eq(index));
			$(this).eq(index).attr("dataId","sp"+index);
		});*/
		for(var i in $("a img")){
			$("a img").eq(i).attr("dataId","sp"+i);
		}
		//点击不同商品跳转不同页面
		
		$("a img").click(function(){
			var $goodsImgid = $(this).attr("dataId");
			$.cookie("PicId",$goodsImgid,{expires:7,path:"/"});
			//小型图
			var $smallPic = json.goodshref[$goodsImgid].smallPic;
			$.cookie("smallPic",$smallPic,{expires:7,path:"/"});
			//中型图
			var $middlePic = json.goodshref[$goodsImgid].middlePic;
			$.cookie("middlePic",$middlePic,{expires:7,path:"/"});
			//大型图
			var $bigPic = json.goodshref[$goodsImgid].bigPic;
			$.cookie("bigPic",$bigPic,{expires:7,path:"/"});
			//商品信息title部分
			var $title = json.goodshref[$goodsImgid].title;
			$.cookie("title",$title,{expires:7,path:"/"});
			//商品尺码部分
			var $size = json.goodshref[$goodsImgid].size;
			$.cookie("size",$size,{expires:7,path:"/"});
			//商品优惠套装部分
			var $favourable = json.goodshref[$goodsImgid].favourable;
			$.cookie("favourable",$favourable,{expires:7,path:"/"});
			location.href = "goodsDetailed.html";
		});
		//对象转字符串
		function convertObjToCartStr(obj) {
			var cartStr = "";
			for(var id in obj) {
				if(cartStr) {
					cartStr += ":";
				}
				cartStr += id + "," + obj[id].name + "," + obj[id].price + "," + obj[id].num + "," + obj[id].src;
			}
			return cartStr;
		}
	});
});
